package com.skzh.web.controller.equipment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.skzh.common.core.domain.model.LoginUser;
import com.skzh.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.skzh.common.annotation.Log;
import io.swagger.annotations.ApiOperation;
import com.skzh.common.core.controller.BaseController;
import com.skzh.common.core.domain.AjaxResult;
import com.skzh.common.enums.BusinessType;
import com.skzh.equipment.domain.HailerAnnouncement;
import com.skzh.equipment.service.IHailerAnnouncementService;
import com.skzh.common.utils.poi.ExcelUtil;
import com.skzh.common.core.page.TableDataInfo;

/**
 * 喊话参数配置Controller
 *
 * @author Lujk
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/equipment/announcement")
public class HailerAnnouncementController extends BaseController {
    @Autowired
    private IHailerAnnouncementService hailerAnnouncementService;

    /**
     * 查询喊话参数配置列表
     */
    @ApiOperation(value = "查询喊话参数配置列表")
    @PreAuthorize("@ss.hasPermi('equipment:announcement:list')")
    @GetMapping("/list" )
    public TableDataInfo list(HailerAnnouncement hailerAnnouncement) {
        startPage();
        List<HailerAnnouncement> list = hailerAnnouncementService.selectHailerAnnouncementList(hailerAnnouncement);
        return getDataTable(list);
    }

    /**
     * 导出喊话参数配置列表
     */
    @ApiOperation(value = "导出喊话参数配置列表")
    @PreAuthorize("@ss.hasPermi('equipment:announcement:export')" )
    @Log(title = "喊话参数配置" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, HailerAnnouncement hailerAnnouncement) {
        List<HailerAnnouncement> list = hailerAnnouncementService.selectHailerAnnouncementList(hailerAnnouncement);
        ExcelUtil<HailerAnnouncement> util = new ExcelUtil<HailerAnnouncement>(HailerAnnouncement. class);
        util.exportExcel(response, list, "喊话参数配置数据" );
    }

    /**
     * 获取喊话参数配置详细信息
     */
    @ApiOperation(value = "获取喊话参数配置详细信息")
    @PreAuthorize("@ss.hasPermi('equipment:announcement:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(hailerAnnouncementService.selectHailerAnnouncementById(id));
    }

    /**
     * 新增喊话参数配置
     */
    @ApiOperation(value = "新增喊话参数配置")
    @PreAuthorize("@ss.hasPermi('equipment:announcement:add')" )
    @Log(title = "喊话参数配置" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HailerAnnouncement hailerAnnouncement) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        hailerAnnouncement.setCreateBy(loginUser.getUsername());
        return toAjax(hailerAnnouncementService.insertHailerAnnouncement(hailerAnnouncement));
    }

    /**
     * 修改喊话参数配置
     */
    @ApiOperation(value = "修改喊话参数配置")
    @PreAuthorize("@ss.hasPermi('equipment:announcement:edit')" )
    @Log(title = "喊话参数配置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HailerAnnouncement hailerAnnouncement) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        hailerAnnouncement.setUpdateBy(loginUser.getUsername());
        return toAjax(hailerAnnouncementService.updateHailerAnnouncement(hailerAnnouncement));
    }

    /**
     * 删除喊话参数配置
     */
    @ApiOperation(value = "删除喊话参数配置")
    @PreAuthorize("@ss.hasPermi('equipment:announcement:remove')" )
    @Log(title = "喊话参数配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(hailerAnnouncementService.deleteHailerAnnouncementByIds(ids));
    }
}
